package com.example.Dietproject.User.controller;

import com.example.Dietproject.User.entity.User;
import com.example.Dietproject.User.servlce.UserServlce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserServlce userServlce;
    @RequestMapping(value = {"/","/login"})
    public String login(){
        return "login";
    }
    @RequestMapping("/type.html")
    public String type(){
        return "type";
    }
    @RequestMapping("/loginUser")
    public String loginUser(User user, HttpSession session){
        User loginUser = userServlce.selectByLogin(user);
        if (loginUser == null) {
            return "login";
        }
        session.setAttribute("User",user);
        return "index";
    }
}
